
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The impact of divorce laws on the equilibrium in the marriage market.
% Ana Reynoso
% April 2024
%
% This file runs the event studies, saves estimation results, and creates:
%
%- Table A1 - Panel A
%- Table A1 - Panel B
%  
% Data: PSID 1968-1992
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/

*%------------------------ Replication Path -------------------------------%

clear all

*%--- Indicate location of Replication folder:
*global replication_location "C:\update_with_your_path"

qui{

*%------------------------ Preliminaries ----------------------------------%
	
cd "$replication_location\Evidence\Output"
u "$replication_location\Data\Inputs\households_psid.dta", clear

*--- Newlyweds
replace year_firstmarriage=s_year_firstmarriage if (year_firstmarriage==9998 | year_firstmarriage==9999) & nbr_marriages==1
replace year_firstmarriage=. if year_firstmarriage==9998 | year_firstmarriage==9999
gen dist= year-year_firstmarriage 
gen newlywed2= (dist==0 | dist==1| dist==2) 
*--- Education 
gen headsed=educ
replace headsed=. if educ>=98
gen wifesed=s_educ
replace wifesed=. if s_educ>=98
*--- State and year dummies
tab state, gen(st_)
forvalues i=1(1)51{
gen sted_`i'=headsed*st_`i'
}
tab year, gen(yr_)
forvalues i=1(1)26{
gen yred_`i'=headsed*yr_`i'
}
forvalues i=1(1)51{
gen stedR_`i'=wifesed*st_`i'
}
forvalues i=1(1)26{
gen yredR_`i'=wifesed*yr_`i'
}
forvalues i=1(1)51{ 
gen lineartrend_`i'=year*st_`i'
}
gen inter=headsed*unilateral
gen interR=wifesed*unilateral
*--- Years since ud
gen years_since_ud = year - ud_year 
gen ever_ud=unilateral
replace ever_ud = 1 if ud_year!=.
tab years_since_ud
gen bin_ysud=.
replace bin_ysud=1 if (years_since_ud==0)
replace bin_ysud=2 if (years_since_ud==1 |years_since_ud==2)
replace bin_ysud=3 if (years_since_ud==3 |years_since_ud==4)
replace bin_ysud=4 if (years_since_ud==5 |years_since_ud==6)
replace bin_ysud=5 if (years_since_ud==7 |years_since_ud==8)
replace bin_ysud=6 if (years_since_ud==9 |years_since_ud==10)
replace bin_ysud=7 if years_since_ud>10 & years_since_ud!=.
replace bin_ysud=8 if (years_since_ud==-1 |years_since_ud==-2)
replace bin_ysud=9 if (years_since_ud==-3 |years_since_ud==-4)
replace bin_ysud=10 if (years_since_ud==-5 |years_since_ud==-6)
replace bin_ysud=11 if (years_since_ud==-7 |years_since_ud==-8)
replace bin_ysud=12 if (years_since_ud==-9 |years_since_ud==-10)
replace bin_ysud=13 if years_since_ud<-10 & years_since_ud!=.
replace bin_ysud=14 if ever_ud==0 
replace bin_ysud=. if unilateral==.
tab bin_ysud, gen(binud_)
*--- Interaction with husband's education
forvalues i=1(1)14{
gen inter2_`i'=headsed*binud_`i'
}

*%------------------------ TABLE A1-Panel A -----------------------------------%
eststo: reg  wifesed inter headsed unilateral i.state i.year sted_*  if s_nbr_marriages==1 & newlywed2==1, cluster(state)  
eststo: reg  wifesed inter2_1-inter2_13 headsed binud_* i.state i.year sted_* if s_nbr_marriages==1 & newlywed2==1, cluster(state)  
eststo: reg  wifesed inter headsed unilateral i.state i.year sted_* lineartrend_* if s_nbr_marriages==1 & newlywed2==1, cluster(state)  
eststo: reg  wifesed inter2_1-inter2_13 headsed binud_* i.state i.year sted_* lineartrend_* if s_nbr_marriages==1 & newlywed2==1, cluster(state)  
esttab using Table_A1_Panel_A.tex, label  se  b(4) star(* 0.10 ** 0.05 *** 0.01) noconstant keep(inter inter2_*) nonotes addnotes("Standard errors clustered at the state level are in parentheses." "***Significant at the 0.01 level. **Significant at the 0.05 level. *Significant at the 0.10 level.") replace
eststo clear

*%------------------------ TABLE A1-Panel B -----------------------------------%
*--- Interaction with wife's education
forvalues i=1(1)14{
gen inter2R_`i'=wifesed*binud_`i'
}
eststo: reg  headsed interR wifesed  unilateral i.state i.year stedR_*  if s_nbr_marriages==1 & newlywed2==1, cluster(state)  
eststo: reg  headsed inter2R_1-inter2R_13 wifesed binud_* i.state i.year stedR_* if s_nbr_marriages==1 & newlywed2==1, cluster(state)  
eststo: reg  headsed interR wifesed  unilateral i.state i.year stedR_* lineartrend_* if s_nbr_marriages==1 & newlywed2==1, cluster(state)  
eststo: reg  headsed inter2R_1-inter2R_13 wifesed binud_* i.state i.year stedR_* lineartrend_* if s_nbr_marriages==1 & newlywed2==1, cluster(state)  
esttab using Table_A1_Panel_B.tex, label  se  b(4) star(* 0.10 ** 0.05 *** 0.01) noconstant keep(interR inter2R_*) nonotes addnotes("Standard errors clustered at the state level are in parentheses." "***Significant at the 0.01 level. **Significant at the 0.05 level. *Significant at the 0.10 level.") replace
eststo clear

*** Export coefficients for Figure 1:

reg  wifesed inter2_1-inter2_13 headsed binud_* i.state i.year sted_* if s_nbr_marriages==1 & newlywed2==1, cluster(state)  
forvalues i=1(1)13{
gen coeff_`i' = _b[inter2_`i']
gen se_`i' = _se[inter2_`i']
}
keep coeff_1-se_13
order coeff_13 coeff_12 coeff_11 coeff_10 coeff_9 coeff_8 coeff_1 coeff_2 coeff_3 coeff_4 coeff_5 coeff_6 coeff_7 se_13 se_12 se_11 se_10 se_9 se_8 se_1 se_2 se_3 se_4 se_5 se_6 se_7 
duplicates drop
export delimited Figure_1_Data, replace

}
